package com.sh.demo.qa.module.rbac.entity;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.JoinColumn;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Access(AccessType.FIELD)
@Table(name="T_USER")
public class User implements Serializable {

	private static final long serialVersionUID = -8286330785662768079L;

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="user")
	@SequenceGenerator(name="user", sequenceName="SEQ_USER")
	@Column(length = 20)
	private Long id;

	@Column(length = 50, nullable = false)
	private String code;

	@Column(length = 50)
	private String name;

	@Column(length = 100)
	private String password;

	@ManyToMany(cascade = { CascadeType.PERSIST })
	@JoinTable(name = "T_USER_ROLE", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
	private Collection<Role> roles;

	// 默认的<shiro:principal/>输出.
    public String toString() {
        return code;
    }
    
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Collection<Role> getRoles() {
		return roles;
	}

	public void setRoles(Collection<Role> roles) {
		this.roles = roles;
	}

}
